return value->value;
}
+void
+gtk_css_icon_effect_apply (GtkCssIconEffect icon_effect,
+ cairo_surface_t *surface)
+{
+ cairo_t *cr;
+
+ switch (icon_effect)
+ {
+ case GTK_CSS_ICON_EFFECT_DIM:
+ cr = cairo_create (surface);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0); /* transparent */
+ cairo_paint_with_alpha (cr, 0.5);
+ cairo_destroy (cr);
+ break;
+
+ case GTK_CSS_ICON_EFFECT_HIGHLIGHT:
+ cr = cairo_create (surface);
+ cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
+ cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
+ /* DANGER: We mask with ourself - that works for images, but... */
+ cairo_mask_surface (cr, surface, 0, 0);
+ cairo_destroy (cr);
+ break;
+
+ default:
+ g_warn_if_reached ();
+ /* fall through */
+ case GTK_CSS_ICON_EFFECT_NONE:
+ break;
+ }
+}
+
/* GtkCssIconStyle */
static const GtkCssValueClass GTK_CSS_VALUE_ICON_STYLE = {
cairo_restore (cr);
}
-static void
-colorshift_source (cairo_t *cr,
- gdouble shift)
-{
- cairo_pattern_t *source;
-
- cairo_save (cr);
- cairo_paint (cr);
-
- source = cairo_pattern_reference (cairo_get_source (cr));
-
- cairo_set_source_rgb (cr, shift, shift, shift);
- cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
-
- cairo_mask (cr, source);
-
- cairo_pattern_destroy (source);
- cairo_restore (cr);
-}
-
static GdkPixbuf *
scale_or_ref (GdkPixbuf *src,
gint width,
}
static GdkPixbuf *
-gtk_do_render_icon_pixbuf (GtkStyleContext *context,
- const GtkIconSource *source,
- GtkIconSize size)
+gtk_render_icon_pixbuf_for_style (GtkCssStyle *style,
+ const GtkIconSource *source,
+ GtkIconSize size)
{
GdkPixbuf *scaled;
GdkPixbuf *stated;
GdkPixbuf *base_pixbuf;
gint width = 1;
gint height = 1;
- cairo_t *cr;
cairo_surface_t *surface;
gboolean wildcarded;
- GtkCssIconEffect image_effect;
+ GtkCssIconEffect icon_effect;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
base_pixbuf = gtk_icon_source_get_pixbuf (source);
if (!wildcarded)
return scaled;
- image_effect = _gtk_css_icon_effect_value_get
- (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT));
+ icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT));
- switch (image_effect)
+ if (icon_effect != GTK_CSS_ICON_EFFECT_NONE)
{
- case GTK_CSS_ICON_EFFECT_DIM:
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- gdk_pixbuf_get_width (scaled),
- gdk_pixbuf_get_height (scaled));
- cr = cairo_create (surface);
- gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
- cairo_paint_with_alpha (cr, 0.5);
-
- cairo_destroy (cr);
-
- g_object_unref (scaled);
- stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
- cairo_image_surface_get_width (surface),
- cairo_image_surface_get_height (surface));
- cairo_surface_destroy (surface);
- break;
-
- case GTK_CSS_ICON_EFFECT_HIGHLIGHT:
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- gdk_pixbuf_get_width (scaled),
- gdk_pixbuf_get_height (scaled));
-
- cr = cairo_create (surface);
- gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
- colorshift_source (cr, 0.10);
-
- cairo_destroy (cr);
-
- g_object_unref (scaled);
+ surface = gdk_cairo_surface_create_from_pixbuf (scaled, 1, NULL);
+ gtk_css_icon_effect_apply (icon_effect, surface);
stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
cairo_surface_destroy (surface);
- break;
-
- default:
- g_warn_if_reached ();
- /* fall through */
- case GTK_CSS_ICON_EFFECT_NONE:
+ }
+ else
+ {
stated = scaled;
- break;
}
return stated;
g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == (GtkIconSize)-1, NULL);
g_return_val_if_fail (source != NULL, NULL);
- return gtk_do_render_icon_pixbuf (context, source, size);
+ return gtk_render_icon_pixbuf_for_style (gtk_style_context_lookup_style (context), source, size);
}
/**